<#assign contextPath=rc.contextPath/> <#include
"/common/__context.html"/> <#assign pageTitle="VIGOR"/> <#assign
pageBreadCrumbs>
<li class="active"><a href="#"
	onclick="loadContext('${contextPath}/role');">角色列表</a></li>
<li class="active">创建角色</li>
</#assign> <#assign currentMenu="menu20-menu3"/>
<script src="${contextPath}/static/js/jquery.bootstrap-duallistbox.js"></script>
<script type="text/javascript">
	jQuery(function($) {
		var demo1 = $('select[name="resources"]')
				.bootstrapDualListbox(
						{
							infoTextFiltered : '<span class="label label-sm">筛选结果</span> {0}/{1}',
							filterTextClear : '显示全部',
							filterPlaceHolder : '关键字',
							infoText : '资源数 : {0}',
							infoTextEmpty : '资源数 : 0'
						});
		var container1 = demo1.bootstrapDualListbox('getContainer');
		container1.find('.btn').addClass('btn-white btn-info btn-bold');

		var roleTemp = false;
		$('#role').blur(function() {
			var role = $('#role').val();
			$.ajax({
				"type" : "get",
				"contentType" : "application/json",
				"url" : "${contextPath}/role/checkRole",
				"dataType" : "json",
				"data" : "role=" + role,
				"success" : function(result) {
					if (result.success) {
						alert("对不起,该角色已存在!");
						$('#role').focus();
					} else {
						roleTemp = true;
					}
				}
			});
		});

		$('#saveBtn').click(function() {
			if (roleTemp == true) {
				$('#createRoleForm').submit();
			}
		});

		//in ajax mode, remove remaining elements before leaving page
		$(document).one(
				'ajaxloadstart.page',
				function(e) {
					$('select[name="duallistbox_demo1[]"]')
							.bootstrapDualListbox('destroy');
				});
	});
</script>
<@mainContext pageTitle=pageTitle pageBreadCrumbs=pageBreadCrumbs
currentMenu=currentMenu>
<!-- pageContent BEGAIN-->
<div class="row">
	<div class="col-xs-12">
		<!-- PAGE CONTENT BEGINS -->
		<form id="createRoleForm" class="form-horizontal" role="form"
			target="formIFrame" method="post" action="${contextPath}/role/create">

			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right" for="role">
					角色名称 </label>

				<div class="col-sm-9">
					<input type="text" id="role" name="role" placeholder="请输入角色名称"
						class="col-xs-10 col-sm-5" />
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right"
					for="description"> 角色描述 </label>

				<div class="col-sm-9">
					<input type="text" id="description" name="description"
						placeholder="请输入角色描述" class="col-xs-10 col-sm-5" />
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-top" for="duallist">
					资源权限 </label>

				<div class="col-sm-8">
					<!-- #section:plugins/input.duallist -->
					<select multiple="multiple" size="10" name="resources"
						id="duallist"> <#list resources as resource>
						<option value="${resource.recid}">#${resource.recid?string('00')}
							-> ${resource.name} -> ${resource.permissions?if_exists}</option> </#list>
					</select>
					<!-- /section:plugins/input.duallist -->
				</div>
			</div>



			<div class="hr hr-16 hr-dotted"></div>

			<div class="col-md-offset-3 col-md-9">
				<button class="btn btn-sm btn-success" id="saveBtn" type="button">
					<i class="ace-icon fa fa-check bigger-110"></i> 保存
				</button>

				&nbsp; &nbsp; &nbsp;
				<button class="btn btn-sm" type="reset">
					<i class="ace-icon fa fa-undo bigger-110"></i> 重置
				</button>
			</div>

		</form>
		<!-- PAGE CONTENT ENDS -->

		<iframe name="formIFrame" style="display: none;"></iframe>

	</div>
	<!-- /.col -->
</div>
<!-- pageContent END -->
</@mainContext>
